package com.guigu.liuyunan.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.guigu.liuyunan.mapper.MealsMapper;
import com.guigu.liuyunan.mapper.MealstypeMapper;
import com.guigu.liuyunan.pojo.LYNPageVo;
import com.guigu.liuyunan.pojo.Meals;
import com.guigu.liuyunan.pojo.Mealstype;
import com.guigu.liuyunan.service.MealsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MealsServiceImpl implements MealsService {

    @Autowired
    MealsMapper mm;

    @Autowired
    MealstypeMapper mt;

    @Override
    public PageInfo mealsInfo(LYNPageVo pageVo) {
        PageHelper.startPage(pageVo.getPage(), pageVo.getNum());
        List<Meals> byPagination =  mm.mealsInfo(pageVo);;
        return new PageInfo(byPagination);
    }

    @Override
    public List<Mealstype> mealsTypeInfo() {
        return mt.mealsTypeInfo();
    }

    @Override
    public int delMeals(Integer id) {
        return mm.deleteByPrimaryKey(id);
    }

    @Override
    public int addMeals(Meals meals) {
        return mm.insert(meals);
    }

    @Override
    public int upMeals(Meals meals) {
        return mm.updateByPrimaryKey(meals);
    }
}
